package com.itheima.day08;

import com.itheima.domain.Student;
import com.itheima.util.RandomUtil;

import java.util.ArrayList;
import java.util.stream.Stream;

public class Test02 {

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 1; i <= 45; i++) {
            Student student = new Student();
            String sid = "";
            if (i <= 9) {
                sid += "A000" + i;
            } else {
                sid = "A00" + i;
            }
            student.setSid(sid);
            student.setName(RandomUtil.getXing() + RandomUtil.getMing());
            student.setGender(RandomUtil.getGender());
            student.setBirthday(RandomUtil.getBirthday());
            student.setPhone(RandomUtil.getPhone());
            student.setWxs(RandomUtil.getWxs());
            student.setGroup((i - 1) / 5 + 1);//i%10+1
            list.add(student);
        }
        for (Student s : list) {
            System.out.println(s);
        }
     /*   System.out.println(getNan(list));
        System.out.println(getNv(list));
        System.out.println(getMing2(list));
        System.out.println(getMing3(list));
        System.out.println(get00(list));
        System.out.println(get66(list));*/
        System.out.println(get1wx(list));
        System.out.println(get2wx(list));

    }

    //男生和女生各自有多少人？    可以
    public static long getNan(ArrayList<Student> list) {
        return list.stream().filter(s -> s.getGender().equals("男")).count();
    }

    public static long getNv(ArrayList<Student> list) {
        return list.stream().filter(s -> s.getGender().equals("女")).count();
    }

    //00后有多少人？    可以
    public static long get00(ArrayList<Student> list) {
        return list.stream().filter(s -> s.getBirthday().getYear() >= 2000).count();
    }


    //名字长度是2的学生有多少人？ 可以
    public static long getMing2(ArrayList<Student> list) {
        return list.stream().filter(s -> s.getName().length() == 2).count();
    }

    //名字长度是3的学生有多少人？ 可以
    public static long getMing3(ArrayList<Student> list) {
        return list.stream().filter(s -> s.getName().length() == 3).count();
    }

    //姓张的同学有多少人？  可以
    public static long getZhang(ArrayList<Student> list) {
        return list.stream().filter(s -> s.getName().startsWith("张")).count();
    }

    //手机号中至少包含2个6的有哪些？  可以
    public static long get66(ArrayList<Student> list) {
        Stream<Student> stream = list.stream().filter(s -> {
            int count = 0;
            String phone = s.getPhone();
            char[] chars = phone.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == '6') {
                    count++;
                }
            }
            return count >= 2;

        });
        return stream.count();
    }
    //手机号中至少包含1个6和1个8的有哪些？  可以
    public static long get68(ArrayList<Student> list) {
        Stream<Student> stream = list.stream().filter(s -> {
            int count6 = 0;
            int count8 = 0;
            String phone = s.getPhone();
            char[] chars = phone.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == '6') {
                    count6++;
                }
                if (chars[i] == '8') {
                    count8++;
                }
            }
            return count6>=1&&count8>=1;

        });
        return stream.count();
    }
    //有2个的微信号的人个数  可以
    public static long get2wx(ArrayList<Student> list) {
        return list.stream().filter(s->s.getWxs().size()==2).count();
    }
    //有1个的微信号的人个数   可以
    public static long get1wx(ArrayList<Student> list) {
        return list.stream().filter(s->s.getWxs().size()==1).count();
    }

}
